package mya.mes.mdc.mongodb;

class RoundTable {

  private final static String COLLECTION_NAME_FREFIX = "MQTT_IN_";
  private final static RoundTable _instance = new RoundTable();
  private final static int MAX_MQTT_IN_COLLECTION_AMOUNT = 8;

  private volatile int tableIndex = 0;


  public static RoundTable getInstance() {
    return _instance;
  }

  public synchronized String getInsertCollectionName() {

    String name = COLLECTION_NAME_FREFIX + tableIndex;

    tableIndex++;

    if (tableIndex == MAX_MQTT_IN_COLLECTION_AMOUNT) {
      tableIndex = 0;
    }

    return name;
  }
}
